package xyz.xtt.exchange.aop;

import org.springframework.aop.Pointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import xyz.xtt.exchange.anno.MyCustomAnnotationProcessor;

@Configuration
public class AopConfig {
	@Bean
	public Pointcut customPointCut() {
		GreetingDynamicPointcut greetingDynamicPointcut = new GreetingDynamicPointcut();
		greetingDynamicPointcut
				.setExpression("execution(public * xyz.xtt.exchange.controller.AopController.index(..)) || execution(public * xyz.xtt.exchange.controller.AopController.info(..))");
		return greetingDynamicPointcut;
	}

	@Bean
	public GreetingAdvice getAdvice() {
		return new GreetingAdvice();
	}

	@Bean
	public DefaultPointcutAdvisor defaultPointcutAdvisor() {
//		AspectJExpressionPointcut cut = new AspectJExpressionPointcut();
//		String expression = "execution(public * xyz.xtt.exchange.controller.AopController.index(..)) || execution(public * xyz.xtt.exchange.controller.AopController.info(..))";
//		cut.setExpression(expression);
		DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
		defaultPointcutAdvisor.setPointcut(customPointCut());
		defaultPointcutAdvisor.setAdvice(getAdvice());
		return defaultPointcutAdvisor;
	}

	@Bean
	public MyCustomAnnotationProcessor myCustomAnnotationProcessor() {
		return new MyCustomAnnotationProcessor();
	}
}
